
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>ffmpeg软解rtsp简单直播 · Aivin开发笔记</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="Aivin">
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-plus/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-versions-select/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-local-video/video-js.min.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../styles/website.css">
        
    

        
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="rtsp服务器.html" />
    
    
    <link rel="prev" href="ffmpeg示例代码.html" />
    

    
        <link rel="shortcut icon" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
        <link rel="bookmark" href='../../assets/images/favicon.ico' type="image/x-icon">
    
    
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    项目说明
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../linux/linux基础.html">
            
                <a href="../linux/linux基础.html">
            
                    
                    linux
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../linux/linux基础.html">
            
                <a href="../linux/linux基础.html">
            
                    
                    linux基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../linux/android底层开发.html">
            
                <a href="../linux/android底层开发.html">
            
                    
                    android底层开发
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../c语言/c基础.html">
            
                <a href="../c语言/c基础.html">
            
                    
                    c
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../c语言/c基础.html">
            
                <a href="../c语言/c基础.html">
            
                    
                    c基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../c++/c++基础.html">
            
                <a href="../c++/c++基础.html">
            
                    
                    c++
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../c++/c++基础.html">
            
                <a href="../c++/c++基础.html">
            
                    
                    c++基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../QT/QT基础.html">
            
                <a href="../QT/QT基础.html">
            
                    
                    QT
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../QT/QT基础.html">
            
                <a href="../QT/QT基础.html">
            
                    
                    QT基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../jni/JNI基础.html">
            
                <a href="../jni/JNI基础.html">
            
                    
                    JNI
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../jni/JNI基础.html">
            
                <a href="../jni/JNI基础.html">
            
                    
                    JNI基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../jni/JNI例子.html">
            
                <a href="../jni/JNI例子.html">
            
                    
                    JNI例子
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../SDL/SDL基础.html">
            
                <a href="../SDL/SDL基础.html">
            
                    
                    SDL
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../SDL/SDL基础.html">
            
                <a href="../SDL/SDL基础.html">
            
                    
                    SDL基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="ffmpeg基础.html">
            
                <a href="ffmpeg基础.html">
            
                    
                    ffmpeg
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="ffmpeg基础.html">
            
                <a href="ffmpeg基础.html">
            
                    
                    ffmpeg基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="ffmpeg示例代码.html">
            
                <a href="ffmpeg示例代码.html">
            
                    
                    ffmpeg示例代码
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.8.3" data-path="ffmpeg软解rtsp简单直播.html">
            
                <a href="ffmpeg软解rtsp简单直播.html">
            
                    
                    ffmpeg软解rtsp简单直播
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.4" data-path="rtsp服务器.html">
            
                <a href="rtsp服务器.html">
            
                    
                    rtsp服务器Windows
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../opencv/opencv模块.html">
            
                <a href="../opencv/opencv模块.html">
            
                    
                    opencv模块
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../opencv/opencv.html">
            
                <a href="../opencv/opencv.html">
            
                    
                    opencv
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../openSLES/openSLES基础.html">
            
                <a href="../openSLES/openSLES基础.html">
            
                    
                    openSLES
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../openSLES/openSLES基础.html">
            
                <a href="../openSLES/openSLES基础.html">
            
                    
                    openSLES基础
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../SoundTouch/移植SoundTouch.html">
            
                <a href="../SoundTouch/移植SoundTouch.html">
            
                    
                    SoundTouch
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../SoundTouch/移植SoundTouch.html">
            
                <a href="../SoundTouch/移植SoundTouch.html">
            
                    
                    移植SoundTouch
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../SoundTouch/实现音频变速和变调.html">
            
                <a href="../SoundTouch/实现音频变速和变调.html">
            
                    
                    实现音频变速和变调
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../openGLES/openGLES基础.html">
            
                <a href="../openGLES/openGLES基础.html">
            
                    
                    openGLES模块
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../openGLES/GLSL基础.html">
            
                <a href="../openGLES/GLSL基础.html">
            
                    
                    GLSL基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12.2" data-path="../openGLES/openglES示例.html">
            
                <a href="../openGLES/openglES示例.html">
            
                    
                    openglES示例
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../视频相关/音视频基础.html">
            
                <a href="../视频相关/音视频基础.html">
            
                    
                    音视频术语-文件格式-协议
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../视频相关/音视频基础.html">
            
                <a href="../视频相关/音视频基础.html">
            
                    
                    音视频基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.2" data-path="../视频相关/RTSP.html">
            
                <a href="../视频相关/RTSP.html">
            
                    
                    RTSP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.3" data-path="../视频相关/RTP.html">
            
                <a href="../视频相关/RTP.html">
            
                    
                    RTP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.4" data-path="../视频相关/RTCP.html">
            
                <a href="../视频相关/RTCP.html">
            
                    
                    RTCP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.5" data-path="../视频相关/H264.html">
            
                <a href="../视频相关/H264.html">
            
                    
                    H264
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.6" data-path="../视频相关/YUV.html">
            
                <a href="../视频相关/YUV.html">
            
                    
                    YUV
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.7" data-path="../视频相关/SurfaceView.html">
            
                <a href="../视频相关/SurfaceView.html">
            
                    
                    SurfaceView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.8" data-path="../视频相关/RTMP.html">
            
                <a href="../视频相关/RTMP.html">
            
                    
                    RTMP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13.9" data-path="../视频相关/AAC详解.html">
            
                <a href="../视频相关/AAC详解.html">
            
                    
                    AAC详解
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../音视频相关代码/音视频相关代码.html">
            
                <a href="../音视频相关代码/音视频相关代码.html">
            
                    
                    音视频相关代码
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../ndk/NDK编译基础.html">
            
                <a href="../ndk/NDK编译基础.html">
            
                    
                    NDK工程编译
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../ndk/NDK编译基础.html">
            
                <a href="../ndk/NDK编译基础.html">
            
                    
                    NDK编译基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.2" data-path="../ndk/cmake方式.html">
            
                <a href="../ndk/cmake方式.html">
            
                    
                    cmake
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.3" data-path="../ndk/Android.mk模板.html">
            
                <a href="../ndk/Android.mk模板.html">
            
                    
                    Android.mk
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15.4" data-path="../ndk/Application.mk模板.html">
            
                <a href="../ndk/Application.mk模板.html">
            
                    
                    Application.mk
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >ffmpeg软解rtsp简单直播</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div class="search-plus" id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#ffmpeg&#x8F6F;&#x89E3;rtsp&#x7B80;&#x5355;&#x76F4;&#x64AD;"><b>1. </b>ffmpeg&#x8F6F;&#x89E3;rtsp&#x7B80;&#x5355;&#x76F4;&#x64AD;</a></li></ul></div><a href="#ffmpeg&#x8F6F;&#x89E3;rtsp&#x7B80;&#x5355;&#x76F4;&#x64AD;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="ffmpeg&#x8F6F;&#x89E3;rtsp&#x7B80;&#x5355;&#x76F4;&#x64AD;"><a name="ffmpeg&#x8F6F;&#x89E3;rtsp&#x7B80;&#x5355;&#x76F4;&#x64AD;" class="anchor-navigation-ex-anchor" href="#ffmpeg&#x8F6F;&#x89E3;rtsp&#x7B80;&#x5355;&#x76F4;&#x64AD;"><i class="fa fa-link" aria-hidden="true"></i></a>1. ffmpeg&#x8F6F;&#x89E3;rtsp&#x7B80;&#x5355;&#x76F4;&#x64AD;</h1>
<p><a href="https://download.csdn.net/user/dengpanwen/uploads" target="_blank">&#x6240;&#x9700;so</a></p>
<pre><code class="lang-c++">#include &lt;jni.h&gt;
#include &lt;string&gt;
#include &lt;android/bitmap.h&gt;
#include &lt;android/native_window.h&gt;
#include &lt;android/native_window_jni.h&gt;

extern &quot;C&quot; {
#include &lt;libavcodec/avcodec.h&gt;
#include &lt;libswscale/swscale.h&gt;
#include &lt;libavformat/avformat.h&gt;
#include &lt;libavutil/avutil.h&gt;
#include &lt;libavutil/frame.h&gt;
#include &lt;libavdevice/avdevice.h&gt;
#include &lt;libavfilter/avfilter.h&gt;
#include &quot;libswresample/swresample.h&quot;
#include &quot;libavutil/opt.h&quot;
#include &quot;libavutil/imgutils.h&quot;
}

static AVPacket *pPacket;
static AVFrame *pAvFrame, *pFrameBGR;
static AVCodecContext *pCodecCtx;
struct SwsContext *pImgConvertCtx;
static AVFormatContext *pFormatCtx;
ANativeWindow* nativeWindow;
ANativeWindow_Buffer windowBuffer;
uint8_t *v_out_buffer;
bool stop;

extern &quot;C&quot;
JNIEXPORT jint JNICALL
Java_com_nazhi_testlive555_FfmpegUtils_openVideo(JNIEnv *env, jclass type, jstring url,
                                                 jobject surface) {
    stop = false;
    // &#x7248;&#x672C;&#x517C;&#x5BB9;
    #if LIBAVCODEC_VERSION_INT &lt; AV_VERSION_INT(55, 28, 1)
    #define av_frame_alloc  avcodec_alloc_frame
    #endif

    pAvFrame = av_frame_alloc();
    pFrameBGR = av_frame_alloc();

    char input_str[500]={0};
    // &#x521D;&#x59CB;&#x5316;rtsp&#x5730;&#x5740;
    sprintf(input_str, &quot;%s&quot;, env-&gt;GetStringUTFChars(url, NULL));
    //&#x7ED1;&#x5B9A;surface &#x548C; ANativeWindow
    nativeWindow = ANativeWindow_fromSurface(env, surface);
    if (0 == nativeWindow){
        return -1;
    }

    //&#x6CE8;&#x518C;&#x7F16;&#x89E3;&#x7801;&#x5668;
    avcodec_register_all();
    //&#x6CE8;&#x518C;&#x6240;&#x6709;&#x7EC4;&#x4EF6;
    av_register_all();
    // &#x521D;&#x59CB;&#x5316;&#x7F51;&#x7EDC;&#x5E93;
    avformat_network_init();
    // &#x6CE8;&#x518C;&#x8BBE;&#x5907;
    avdevice_register_all();

    pFormatCtx = avformat_alloc_context();
    // &#x6253;&#x5F00;rtsp&#x6D41;
    if (avformat_open_input(&amp;pFormatCtx, input_str, NULL, NULL) &lt; 0)
    {
        return 1;
    }
    // &#x83B7;&#x53D6;&#x97F3;&#x9891;&#x4FE1;&#x606F;
    avformat_find_stream_info(pFormatCtx, NULL);

    int videoIndex = -1;
    //&#x904D;&#x5386;&#x627E;&#x5230;&#x7684;&#x89C6;&#x97F3;&#x9891;&#x6D41;
    for (unsigned int i = 0; i &lt; pFormatCtx-&gt;nb_streams; i++)
    {
        // &#x627E;&#x5230;&#x89C6;&#x9891;&#x6D41;
        if (pFormatCtx-&gt;streams[i]-&gt;codec-&gt;codec_type == AVMEDIA_TYPE_VIDEO) {
            videoIndex = i;
            break;
        }
    }

    // &#x83B7;&#x5F97;&#x89E3;&#x7801;&#x9700;&#x8981;&#x7684;&#x76F8;&#x5173;&#x4FE1;&#x606F;
    pCodecCtx = pFormatCtx-&gt;streams[videoIndex]-&gt;codec;

    // &#x83B7;&#x5F97; &#x7F16;&#x7801;&#x5668;&#x76F8;&#x5173;&#x4FE1;&#x606F;
    AVCodec *pCodec = avcodec_find_decoder(pCodecCtx-&gt;codec_id);
    //&#x4E3A;&#x5404;&#x79CD;&#x7ED3;&#x6784;&#x4F53;&#x5206;&#x914D;&#x5185;&#x5B58; &#x548C;&#x4E00;&#x4E9B;&#x5FC5;&#x8981;&#x7684;&#x68C0;&#x67E5;
    avcodec_open2(pCodecCtx, pCodec, NULL);

    int width = pCodecCtx-&gt;width;
    int height = pCodecCtx-&gt;height;

    // &#x8BA1;&#x7B97;&#x7F13;&#x51B2;&#x533A;&#x586B;&#x5145;&#x6240;&#x9700;&#x7684;&#x5927;&#x5C0F;
    int numBytes = av_image_get_buffer_size(AV_PIX_FMT_RGBA, width, height, 1);
    v_out_buffer = (uint8_t *)av_malloc(numBytes*sizeof(uint8_t));

    // &#x7ED9;&#x50CF;&#x7D20;&#x6570;&#x636E;&#x5206;&#x914D;&#x7A7A;&#x95F4;
    av_image_fill_arrays(pFrameBGR-&gt;data, pFrameBGR-&gt;linesize, v_out_buffer, AV_PIX_FMT_RGBA, width, height, 1);

    //SwsContext &#x4E3B;&#x8981;&#x7528;&#x4E8E;&#x89C6;&#x9891;&#x56FE;&#x50CF;&#x7684;&#x8F6C;&#x6362; &#xFF0C;sws_getContext&#x521D;&#x59CB;&#x5316;
    pImgConvertCtx = sws_getContext(
            pCodecCtx-&gt;width,             //&#x539F;&#x59CB;&#x5BBD;&#x5EA6;
            pCodecCtx-&gt;height,            //&#x539F;&#x59CB;&#x9AD8;&#x5EA6;
            pCodecCtx-&gt;pix_fmt,           //&#x539F;&#x59CB;&#x683C;&#x5F0F;
            pCodecCtx-&gt;width,             //&#x76EE;&#x6807;&#x5BBD;&#x5EA6;
            pCodecCtx-&gt;height,            //&#x76EE;&#x6807;&#x9AD8;&#x5EA6;
            AV_PIX_FMT_RGBA,              //&#x76EE;&#x6807;&#x683C;&#x5F0F;
            SWS_BICUBIC,                  //&#x7B97;&#x6CD5;&#x7C7B;&#x578B;
            NULL,
            NULL,
            NULL);

    // &#x8BBE;&#x7F6E; ANativeWindow &#x7684;&#x7F13;&#x5B58;&#x5927;&#x5C0F; ,&#x8FD4;&#x56DE;&#x503C; &lt; 0 &#x8868;&#x793A;&#x5931;&#x8D25;
    if ( ANativeWindow_setBuffersGeometry(nativeWindow,width,height,WINDOW_FORMAT_RGBA_8888) &lt;0 ){
        ANativeWindow_release(nativeWindow);
        return -1;
    }


    // &#x7ED9; AVPacket &#x5206;&#x914D;&#x5185;&#x5B58;
    pPacket = (AVPacket*)av_malloc(sizeof(AVPacket));

    while (!stop) {
        // &#x83B7;&#x5F97;&#x4E00;&#x5E27;&#x89C6;&#x9891;&#x7684;&#x538B;&#x7F29;&#x6570;&#x636E;
        if (av_read_frame(pFormatCtx, pPacket) &gt;= 0) {
            if ((pPacket)-&gt;stream_index != videoIndex) {
                continue;
            }

            int gotPicCount = 0;
            //&#x89E3;&#x7801; ,  &#x89E3;&#x7801;&#x5931;&#x8D25; gotPicCount &#x8FD4;&#x56DE;&#x503C;&#x4E3A;0
            avcodec_decode_video2(pCodecCtx, pAvFrame, &amp;gotPicCount, pPacket);
            if (gotPicCount != 0) {
                // &#x8F6C;&#x6362;&#x50CF;&#x7D20;
                sws_scale(
                        pImgConvertCtx,
                        (const uint8_t *const *) pAvFrame-&gt;data,
                        pAvFrame-&gt;linesize,
                        0,
                        pCodecCtx-&gt;height,
                        pFrameBGR-&gt;data,
                        pFrameBGR-&gt;linesize);

                // &#x9501;&#x5B9A; ANativeWindow , &#x8FD4;&#x56DE;&#x503C; &#x5C0F;&#x4E8E;0 &#x4EE3;&#x8868;&#x5931;&#x8D25;
                if (ANativeWindow_lock(nativeWindow, &amp;windowBuffer, NULL) &gt;= 0)
                {
                    uint8_t *dst = (uint8_t *) windowBuffer.bits;
                    for (int h = 0; h &lt; height; h++)
                    {
                        // &#x5C06;&#x6570;&#x636E;&#x62F7;&#x8D1D;&#x5230; ANativeWindow &#x4EE5;&#x4FBF;&#x89E3;&#x7801;&#x3001;&#x663E;&#x793A;
                        memcpy(dst + h * windowBuffer.stride * 4,
                               v_out_buffer + h * pFrameBGR-&gt;linesize[0],
                               pFrameBGR-&gt;linesize[0]);
                    }
                    // &#x91CA;&#x653E;&#x9501;&#x5B9A; ANativeWindow
                    ANativeWindow_unlockAndPost(nativeWindow);
                }
            }
        }
        // &#x91CD;&#x7F6E; AVPacket
        av_packet_unref(pPacket);
    }
    // &#x91CA;&#x653E; SwsContext
    sws_freeContext(pImgConvertCtx);
    //&#x91CA;&#x653E;
    av_free(pPacket);
    av_free(pFrameBGR);
    // &#x5173;&#x95ED; AVCodecContext
    avcodec_close(pCodecCtx);
    // &#x5173;&#x95ED; AVFormatContext
    avformat_close_input(&amp;pFormatCtx);
    return 1;
}


extern &quot;C&quot;
JNIEXPORT void JNICALL
Java_com_nazhi_testlive555_FfmpegUtils_stop(JNIEnv *env, jclass type) {
    stop = true;
}
</code></pre>
<footer class="page-footer"><span class="copyright">&#x65E0;&#x7248;&#x6743; &#x53EF;&#x4EE5;&#x65E0;&#x9650;&#x5236;&#x4F7F;&#x7528;&#xFF01; all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x66F4;&#x65B0;&#x65F6;&#x95F4;&#xFF1A;
2019-12-18 14:42:27
</span></footer>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="ffmpeg示例代码.html" class="navigation navigation-prev " aria-label="Previous page: ffmpeg示例代码">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="rtsp服务器.html" class="navigation navigation-next " aria-label="Next page: rtsp服务器Windows">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"ffmpeg软解rtsp简单直播","level":"1.8.3","depth":2,"next":{"title":"rtsp服务器Windows","level":"1.8.4","depth":2,"path":"chinese/ffmpeg/rtsp服务器.md","ref":"chinese/ffmpeg/rtsp服务器.md","articles":[]},"previous":{"title":"ffmpeg示例代码","level":"1.8.2","depth":2,"path":"chinese/ffmpeg/ffmpeg示例代码.md","ref":"chinese/ffmpeg/ffmpeg示例代码.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","search-plus","todo","anchor-navigation-ex","copy-code-button","versions-select","fontsettings","sharing","tbfed-pagefooter","donate","local-video","splitter","edit-link","expandable-chapters","favicon","theme-comscore","local-video"],"styles":{"website":"styles/website.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"无版权 可以无限制使用！","modify_label":"该文件更新时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"todo":{},"splitter":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"versions-select":{"type":"branches"},"donate":{"alipay":"https://gitee.com/hnyer/filesOfGitbook/raw/master/files/201803011956_osChina_支付宝收款码.png","alipayText":"支付宝打赏","button":"打赏","title":"","wechat":"https://gitee.com/hnyer/filesOfGitbook/raw/master/files/201803011956_osChina_微信收款码.png","wechatText":"微信打赏"},"fontsettings":{"family":"sans","size":2,"theme":"sepia"},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":true},"favicon":{"shortcut":"assets/images/favicon.ico","bookmark":"assets/images/favicon.ico"},"theme-comscore":{},"local-video":{},"copy-code-button":{},"versions":{"options":[{"value":"https://www.aivin666.cn/java_android/","text":"v1.0"}]},"sharing":{"all":["facebook","google","twitter","weibo","instapaper"],"facebook":false,"google":true,"instapaper":false,"twitter":false,"vk":false,"weibo":true},"edit-link":{"label":"托管页面","base":"https://www.baidu.com/"},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"expandable-chapters":{},"search-plus":{}},"theme":"default","author":"Aivin","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Aivin开发笔记","language":"zh-hans","gitbook":"*","description":"Aivin开发笔记"},"file":{"path":"chinese/ffmpeg/ffmpeg软解rtsp简单直播.md","mtime":"2019-12-18T06:42:27.153Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-12-24T10:38:14.517Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-plus/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-versions-select/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-local-video/video.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-edit-link/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-expandable-chapters/expandable-chapters.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

